package cn.zyq.ykb.controller.mgt.task;

import cn.zyq.ykb.beans.task.TaskPackage;
import cn.zyq.ykb.beans.task.bo.RemovePackageBo;
import cn.zyq.ykb.beans.task.bo.TaskPackageBo;
import cn.zyq.ykb.service.task.TaskPackageService;
import cn.zyq.ykb.service.task.TaskService;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 任务包Controller
 *
 * @author SystemAuth
 * @date 2023-06-01
 */

@RestController(value = "mgtTaskPackageController")
@RequestMapping("/mgt/taskPackage")
@Api(tags = "任务包接口")
public class TaskPackageController extends BaseController {

    @Autowired
    private TaskPackageService taskPackageService;
    @Autowired
    private TaskService taskService;

    /**
     * 查询任务包列表
     */
    @ApiOperation(value = "列表", response = TaskPackage.class)
    @PreAuthorize("@ss.hasPermi('ykb:taskPackage:list')")
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.taskPackageService.selectTaskPackageList(pageParam);
    }

     /**
      * 导出任务包列表
      */
     @ApiOperation(value = "导出")
     @PreAuthorize("@ss.hasPermi('ykb:taskPackage:export')")
     @Log(title = "任务包" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, TaskPackage taskPackage) {
         List<TaskPackage> list = taskPackageService.selectTaskPackageList(taskPackage);
         ExcelUtil<TaskPackage> util = new ExcelUtil<TaskPackage>(TaskPackage. class);
         util.exportExcel(response, list, "任务包数据");
     }

    /**
     * 获取任务包详细信息
     */
    @ApiOperation(value = "详情", response = TaskPackage.class)
    @PreAuthorize("@ss.hasPermi('ykb:taskPackage:query')")
    @GetMapping(value = "/{taskPackageID}")
    public Object getInfo(@PathVariable("taskPackageID") Integer taskPackageID) {
        return this.taskPackageService.selectTaskPackageByTaskPackageID(taskPackageID);
    }
    /**
     * 获取任务包详细信息
     */
    @ApiOperation(value = "详情", response = TaskPackage.class)
    @PreAuthorize("@ss.hasPermi('ykb:taskPackage:query')")
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.taskPackageService.selectTaskPackageByServiceID(serviceID);
    }

    /**
     * 新增任务包
     */
    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('ykb:taskPackage:add')")
    @Log(title = "任务包", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody TaskPackage taskPackage) {
        return this.taskPackageService.insertTaskPackage(taskPackage);
    }

    /**
     * 修改任务包
     */
    @ApiOperation(value = "编辑")
    @PreAuthorize("@ss.hasPermi('ykb:taskPackage:edit')")
    @Log(title = "任务包", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody TaskPackage taskPackage) {
        return this.taskPackageService.updateTaskPackage(taskPackage);
    }

    /**
     * 删除任务包
     */
    @ApiOperation(value = "删除")
    @PreAuthorize("@ss.hasPermi('ykb:taskPackage:remove')")
    @Log(title = "任务包", businessType = BusinessType.DELETE)
    @DeleteMapping("/{taskPackageIDs}")
    public Object remove(@PathVariable Integer[] taskPackageIDs) {
        return this.taskPackageService.deleteTaskPackageByTaskPackageIDs(taskPackageIDs);
    }

    /**
     * 上下架
     */
    @ApiOperation(value = "上下架")
    @PreAuthorize("@ss.hasPermi('ykb:taskPackage:remove')")
    @Log(title = "任务包", businessType = BusinessType.DELETE)
    @GetMapping("upAndDown/{taskPackageID}")
    public Object upAndDown(@PathVariable("taskPackageID") Integer taskPackageID) {
        return this.taskPackageService.upAndDown(taskPackageID);
    }

    /**
     * 查询任务包列表
     */
    @ApiOperation(value = "任务包详情搜索", response = TaskPackage.class)
    @PreAuthorize("@ss.hasPermi('ykb:taskPackage:selectByName')")
    @PostMapping("/selectByName")
    public Object selectByName(@RequestBody TaskPackageBo bo) {
        return this.taskService.selectByName(bo);
    }

    /**
     * 查询任务包列表
     */
    @ApiOperation(value = "移出任务包", response = TaskPackage.class)
    @PreAuthorize("@ss.hasPermi('ykb:taskPackage:selectByName')")
    @PostMapping("/removePackage")
    public Object removePackage(@RequestBody RemovePackageBo bo) {
        return this.taskService.removePackage(bo,this.getLoginSysAdmin());
    }
    /**
     * 获取任务包
     */
    @ApiOperation(value = "获取任务包", response = TaskPackage.class)
    @PreAuthorize("@ss.hasPermi('ykb:taskPackage:list')")
    @PostMapping("/getList")
    public Object getList() {
        return this.taskPackageService.getList();
    }
}
